package com.xujianlun.cpms.controller.sys;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xujianlun.cpms.common.Response;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


import com.xujianlun.cpms.service.sys.IValidationService;
import com.xujianlun.cpms.entity.sys.Validation;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 邮箱验证码 前端控制器
 * </p>
 *
 * @author xujianlun
 * @since 2022-12-06
 */
@RestController
@RequestMapping("/validation")
public class ValidationController {

    @Resource
    private IValidationService validationService;

    // 新增或者更新
    @PostMapping
    public Response save(@RequestBody Validation validation) {
        validationService.saveOrUpdate(validation);
        return Response.success();
    }

    @DeleteMapping("/{id}")
    public Response delete(@PathVariable Integer id) {
        validationService.removeById(id);
        return Response.success();
    }

    @PostMapping("/del/batch")
    public Response deleteBatch(@RequestBody List<Integer> ids) {
        validationService.removeByIds(ids);
        return Response.success();
    }

    @GetMapping
    public Response findAll() {
        return Response.success(validationService.list());
    }

    @GetMapping("/{id}")
    public Response findOne(@PathVariable Integer id) {
        return Response.success(validationService.getById(id));
    }

    @GetMapping("/page")
    public Response findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize) {
        QueryWrapper<Validation> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return Response.success(validationService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

}

